home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / GridSizeDialog.cpp < prev    next >
Text File  |  1997-08-26  |  3KB  |  138 lines

  1. /*
  2.  *    File:        GridSizeDialog.cpp
  3.  *    Function:    A dialog that allows the user to change the view container's grid size.
  4.  *    Written by:    Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *    Change History (most recent first):
  10.  *
  11.  *         <->     2/03/97    JDJ        Created
  12.  */
  13.  
  14. #include "GridSizeDialog.h"
  15.  
  16. #include <ZApplication.h>
  17. #include <ZDialogHandler.h>
  18. #include <ZTextBox.h>
  19.  
  20. #include "DialogBoxProxy.h"
  21. #include "WindowProxy.h"
  22.  
  23.  
  24. // ===================================================================================
  25. //    class CGridSizeDialog
  26. // ===================================================================================
  27.  
  28. static TReanimatorRegister<CGridSizeDialog> sGridSizeRegistrar;
  29.  
  30. //---------------------------------------------------------------
  31. //
  32. // CGridSizeDialog::~CGridSizeDialog
  33. //
  34. //---------------------------------------------------------------
  35. CGridSizeDialog::~CGridSizeDialog()
  36. {
  37. }
  38.  
  39.  
  40. //---------------------------------------------------------------
  41. //
  42. // CGridSizeDialog::CGridSizeDialog
  43. //
  44. //---------------------------------------------------------------
  45. CGridSizeDialog::CGridSizeDialog()
  46. {
  47. }
  48.  
  49.  
  50. //---------------------------------------------------------------
  51. //
  52. // CGridSizeDialog::Create (MReanimatable*)                [static]
  53. //
  54. //---------------------------------------------------------------
  55. MReanimatable* CGridSizeDialog::Create(MReanimatable* parent)
  56. {
  57.     ASSERT(parent == nil);
  58.     
  59.     if (CWindowProxy::msUseProxy)
  60.         return CDialogBoxProxy::Create(parent);
  61.     else
  62.         return new CGridSizeDialog;
  63. }
  64.  
  65.  
  66. //---------------------------------------------------------------
  67. //
  68. // CGridSizeDialog::Pose
  69. //
  70. //---------------------------------------------------------------
  71. bool CGridSizeDialog::Pose(TSize* size)
  72. {
  73.     ASSERT(size != nil);
  74.     
  75.     CGridSizeDialog* dialog = dynamic_cast<CGridSizeDialog*>(TDialogBox::Create(205, TApplication::Instance()));
  76.     dialog->SetData(*size);
  77.     
  78.     string message = kNothingMessage;
  79.                 
  80.     {
  81.     TDialogHandler handler(dialog);
  82.         dialog->Show();
  83.                 
  84.         while (message != kCancelMessage && message != kOKMessage) {
  85.             message = handler.ProcessNextEvent();
  86.             
  87.             if (message == kOKMessage && !dialog->Validate())
  88.                 message = kNothingMessage;
  89.         }
  90.     }
  91.     
  92.     if (message == kOKMessage)
  93.         *size = dialog->GetData();
  94.     
  95.     return message == kOKMessage;
  96. }
  97.  
  98.  
  99. //---------------------------------------------------------------
  100. //
  101. // CGridSizeDialog::SetData
  102. //
  103. //---------------------------------------------------------------
  104. void CGridSizeDialog::SetData(const TSize& size)
  105. {
  106.     TTextBox* textbox = nil;
  107.     
  108.     textbox = dynamic_cast<TTextBox*>(this->FindSubPane("Width"));
  109.     textbox->SetValue(size.width);
  110.     textbox->SelectAll();
  111.  
  112.     textbox = dynamic_cast<TTextBox*>(this->FindSubPane("Height"));
  113.     textbox->SetValue(size.height);
  114. }
  115.  
  116.  
  117. //---------------------------------------------------------------
  118. //
  119. // CGridSizeDialog::GetData
  120. //
  121. //---------------------------------------------------------------
  122. TSize CGridSizeDialog::GetData() const
  123. {
  124.     TSize size;
  125.     
  126.     TTextBox* textbox = nil;
  127.  
  128.     textbox = dynamic_cast<TTextBox*>(this->FindSubPane("Width"));
  129.     size.width = textbox->GetValue();
  130.     
  131.     textbox = dynamic_cast<TTextBox*>(this->FindSubPane("Height"));
  132.     size.height = textbox->GetValue();
  133.  
  134.     return size;
  135. }
  136.  
  137.  
  138.